package net.factoryOpen.core.quickfactory.manufacturing.qua;

import net.factoryOpen.core.common.codeManager.BillcodeManager;
import net.factoryOpen.core.common.exception.StatusUnavailableException;
import net.factoryOpen.core.common.status.BillStatus;
import net.factoryOpen.quickfactory.manufacturing.qua.domain.ExeInspectSelf;
import net.factoryOpen.quickfactory.manufacturing.qua.mapper.ExeInspectSelfMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author factoryOpen
 * @date 2025-06-01
 * @version 1.0.0-draft.0
 */
@Service
public class ExeInspectSelfAlgorithm
{
    @Autowired(required = false)
    private ExeInspectSelfMapper exeInspectSelfMapper;

    @Autowired
    private BillcodeManager billcodeManager;

      /**
       * 请判
       *
       * @param exeInspectSelf 请判
       * @return 结果
       */
      public int requestDeal(ExeInspectSelf exeInspectSelf) throws Exception{
          //防呆检查
          ExeInspectSelf inspectSelf=exeInspectSelfMapper.selectExeInspectSelfById(exeInspectSelf.getId());
          if (inspectSelf.getStatus()!= BillStatus.BASE_DRAFT){
              String msg = "自检异常[" + inspectSelf.getBillNo() + "]的状态不是[0-底稿]";
              throw new StatusUnavailableException(msg);
          }

          //更新状态
          inspectSelf.setStatus(BillStatus.ACTIVE_PROCESS_REQ);
          inspectSelf.refreshUpdatingStamp();
          exeInspectSelfMapper.updateExeInspectSelf(inspectSelf);

          return 1;
      }

}
